Open memory stream.
public bool OpenStream(bool Buffered, bool Dynamic, ref byte[] MemStream, uint StreamSize, TStreamFormat nFormat);
Parameters |
Description |
bool Buffered |
Specifies if stream is buffered stream. True specifies buffered stream. False specifies non bufferd stream. |
bool Dynamic |
Specifies if stream is dynamic or static. True specifies dynamic stream. False specifies static stream. |
ref byte[] MemStream |
Reference of memory block with stream data. |
uint StreamSize |
Size of memory block, in bytes. |
TStreamFormat nFormat |
Stream format. This value can't be sfAutodetect. You must specify valid stream format. |
Return Values |
Description |
True |
All OK. |
False |
Error. To get error message read here. |
First block of data needs to be large enough and must contain all data to identify specified stream type.
For sfMp3 stream format, this block of data needs to contain at least one valid mp3 frame.
For sfOgg streamformat, this block must contain enough data to identify ogg type.
For sfWave, this block must contain valid RIFF header.
If this function fails, call this function again with larger block of data or with another block of data.
For sfMp3 stream, 128 kbps at 44100 Hz you need at least 426 bytes without ID3v2 data at stream start. If input block is too small, function will fail. Then you need to send larger block.
Buffered stream allocates internal memory for input data and class makes copy of input data. User can destroy input data because there is copy of this data in internal buffer. Class will manage this internal memory.
If stream is not buffered, function takes only pointer to stream data. User is responsible for this data. So, user must keep this data in memory until function is done with this data. See IsStreamDataFree.
If you specify dynamic stream, you can add new data into this stream with PushDataToStream function. Use OpenStream with small chunk of input data and add rest of data with PushDataToStream function later. Use SetCallbackFunc and callback mechanism to determine when class needs more data. You can't seek or use reverse mode on dynamic stream. If dynamic stream runs out of data, it waits for new data, playing is paused, wave output is still active and class is ready to continue playing when you push new data to stream with PushDataToStream.
If stream is not dynamic, you can't add new data into stream. Class will use only data provided by sMemStream parameter. But this type of stream has no limitation in seek and reverse mode. When this stream runs out of data, playing is stopped.
Open static stream.
System.IO.FileInfo fInfo = new System.IO.FileInfo(OpenFileDialog1.FileName); long numBytes = fInfo.Length; System.IO.FileStream fStream = new System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader br = new System.IO.BinaryReader(fStream); byte[] stream_data = null; stream_data = br.ReadBytes(System.Convert.ToInt32((int)(numBytes))); if (!(player.OpenStream(true, false, ref stream_data, System.Convert.ToUInt32(numBytes), format))) { MessageBox.Show(player.GetError(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); } br.Close(); fStream.Close();
Copyright (c) 2010. Zoran Cindori - All rights reserved.
Web: http://libzplay.sourceforge.net/ Email: zcindori@inet.hr |